# Create your models here.


from django.db import models

from utils.models import CoreModel


class hangyefenlei(CoreModel):
    index_code = models.CharField(max_length=100, verbose_name="指数代码", null=True, blank=True)
    industry_name = models.CharField(max_length=100, verbose_name="行业名称", null=True, blank=True)
    parent_code = models.CharField(max_length=100, verbose_name="父级代码", null=True, blank=True)  # windows、centos、小写
    level = models.CharField(max_length=100, verbose_name="行业分级（L1/L2/L3）")
    industry_code = models.CharField(max_length=100, verbose_name="行业代码")  # True开启 False关闭
    is_pub = models.CharField(max_length=100, verbose_name="是否发布了指数")
    src = models.CharField(max_length=100, verbose_name="行业分类（SW申万）")
    trace_date = models.DateField(auto_now_add=True, null=False, blank=False, help_text="交易日",
                                  verbose_name="交易日")

    class Meta:
        app_label = 'hangyefenlei'
        db_table = 'tb_hangyefenlei'
        verbose_name = "行业分类"
        verbose_name_plural = verbose_name
        constraints = [
            models.UniqueConstraint(
                fields=['trace_date', 'index_code'],  # 联合字段
                name='unique_trace_date_index_code'  # 约束名称（需唯一）
            )
        ]
